package com.example.backend.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * 批量操作结果DTO
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class BatchResult {
    private int successCount;
    private int totalCount;
    private int failureCount;
    @Builder.Default
    private List<String> errors = new ArrayList<>();
    
    public static BatchResult of(int successCount, int totalCount) {
        return BatchResult.builder()
                .successCount(successCount)
                .totalCount(totalCount)
                .failureCount(totalCount - successCount)
                .build();
    }
    
    /**
     * 添加错误信息
     * @param error 错误信息
     */
    public void addError(String error) {
        if (errors == null) {
            errors = new ArrayList<>();
        }
        errors.add(error);
    }
    
    /**
     * 检查是否有错误
     * @return 是否有错误
     */
    public boolean hasErrors() {
        return errors != null && !errors.isEmpty();
    }
    
    /**
     * 获取错误数量
     * @return 错误数量
     */
    public int getErrorCount() {
        return errors != null ? errors.size() : 0;
    }
}